public class InStringHandler implements StateHandler {
    private final StateMachine stateMachine;

    public InStringHandler(StateMachine stateMachine) {
        this.stateMachine = stateMachine;
    }

    @Override
    public void handleChar(char ch, StringBuilder currentString, StateMachine stateMachine) {
        if (ch == '\\') {
            stateMachine.setState(State.ESCAPE_CHAR);
        } else if (ch == '"') {
            stateMachine.setState(State.STRING_END);
            stateMachine.printCurrentString(currentString);
            stateMachine.resetCurrentString(currentString);
        } else {
            currentString.append(ch);
        }
    }
}